package com.lynn.accesstoken.controller;

import com.lynn.accesstoken.bean.User;
import com.lynn.accesstoken.redis.RedisManager;
import com.lynn.accesstoken.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName HelloController
 * @Description TODO
 * @Author ly
 * @Date 2019-05-30 15:12
 * @Version 1.0
 */
@Controller
@RequestMapping("/openApi")
public class HelloController {

    @Autowired
    RedisManager redisManager;

    @Autowired
    private IUserService userService;

    @RequestMapping("/hello")
    public String hello() {
        Object hello = redisManager.get("hello");
        if (StringUtils.isEmpty(hello)) {
            System.out.println("插入数据");
            redisManager.set("hello", System.currentTimeMillis() + "", 100);
        }
        System.out.println(hello);
        User u = userService.load();
        System.out.println(u);
        return "index";
    }

    @ResponseBody
    @RequestMapping("/findOne")
    public User findUser(String token){
        return userService.findOne(token);
    }
}
